# UDP大小写转换服务器
import socket


def run_udp_server():
    # 创建UDP套接字
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # 绑定地址和端口
    server_address = ('localhost', 12000)
    server_socket.bind(server_address)

    print(f"服务器启动，监听地址: {server_address}")

    while True:
        # 接收客户端消息
        message, client_address = server_socket.recvfrom(2048)
        # 转换为大写
        modified_message = message.decode().upper()
        # 发送回客户端
        server_socket.sendto(modified_message.encode(), client_address)
        print(f"已将消息转换并返回给客户端: {client_address}")


if __name__ == "__main__":
    run_udp_server()
